using System.Reflection;
using SqlSugar;

namespace Shared.SqlSugarCore.Helper;

public static class SqlSugarCodeFirstHelper
{
    public static void InitTables(ISqlSugarClient db, IEnumerable<Type> entityTypes)
    {
        db.DbMaintenance.CreateDatabase();
        
        var types = entityTypes.Where(x => x.GetCustomAttribute<SplitTableAttribute>() is null).ToList();
        
        if (types.Count > 0)
        {
            db.CopyNew().CodeFirst.InitTables(types.ToArray());
        }
    }
}